package com.designpattern.factory;

/**
 * 项目名称: java_algorithm
 * @ClassName AbstractFactoryTest
 * @Description
 * @Author huipanxing huipanxing@chinasofti.com   @Date 2021/9/7 15:24
 */
public class AbstractFactoryTest {

    public static void main(String[] args) {
        IDatabaseUtils iDatabaseUtils = new MysqlDataBaseUtils();
        IConnection connection = iDatabaseUtils.getConnection();
        connection.connect();
        ICommand command = iDatabaseUtils.getCommand();
        command.command();
    }
}

interface IConnection {
    void connect();
}

class MysqlConnection implements IConnection {

    @Override
    public void connect() {
        System.out.println("mysql connect");
    }
}

class OracleConnection implements IConnection {

    @Override
    public void connect() {
        System.out.println("oracle connect");
    }
}

interface ICommand {
    void command();
}

class MysqlCommand implements ICommand {

    @Override
    public void command() {
        System.out.println("mysql command");
    }
}

class OracleCommand implements ICommand {

    @Override
    public void command() {
        System.out.println("oracle command");
    }
}

interface IDatabaseUtils {

    IConnection getConnection();

    ICommand getCommand();

}

class MysqlDataBaseUtils implements IDatabaseUtils{

    @Override
    public IConnection getConnection() {
        return new MysqlConnection();
    }

    @Override
    public ICommand getCommand() {
        return new MysqlCommand();
    }
}
class OracleDataBaseUtils implements IDatabaseUtils{

    @Override
    public IConnection getConnection() {
        return new OracleConnection();
    }

    @Override
    public ICommand getCommand() {
        return new OracleCommand();
    }
}